package initialize

import (
	"fmt"
	"net/http"
	"server/global"
	"server/router"
	"time"

	"github.com/gin-gonic/gin"
)

func ListenAndServe() {
	gin.SetMode(global.CONFIG.System.Mode)

	// readTimeout := setting.ServerSetting.ReadTimeout
	// writeTimeout := setting.ServerSetting.WriteTimeout
	hander := router.InitRouter()
	addr := fmt.Sprintf(":%v", global.CONFIG.System.Addr)

	server := &http.Server{
		Addr:           addr,
		Handler:        hander,
		ReadTimeout:    10 * time.Second,
		WriteTimeout:   10 * time.Second,
		MaxHeaderBytes: 1 << 20,
	}
	time.Sleep(10 * time.Microsecond)

	global.LOG.Info(fmt.Sprintf("start http server listening %s", addr))

	server.ListenAndServe()
}
